public class PalindromeConverter {
    public static String convertToPalindrome(String s) {
        if (s == null || s.length() <= 1) {
            return s;
        }
        
        StringBuilder result = new StringBuilder(s);
        int i = 0, j = s.length() - 1;
        
        while (i < j) {
            if (s.charAt(i) == s.charAt(j)) {
                i++;
                j--;
            } else {
                result.insert(j + 1, s.charAt(i));
                i++;
            }
        }
        
        return result.toString();
    }

    public static void main(String[] args) {
        String[] testCases = {"abcd", "aba", "abc", "aabb", "race"};
        
        for (String test : testCases) {
            String palindrome = convertToPalindrome(test);
            System.out.println("原字符串: " + test);
            System.out.println("最小回文串: " + palindrome);
            System.out.println("添加的字符数: " + (palindrome.length() - test.length()));
            System.out.println();
        }
    }
}

